package day08;

import sun.nio.cs.ext.MS874;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;

public class Demo03 {
    public static void main(String[] args) {
        List<String> list = (List<String>) Proxy.newProxyInstance(
                Demo03.class.getClassLoader(),
                new Class[]{List.class},
                new CallHandler<String>()
        );
        list.add("TOm");
        list.add("Jerry");
        System.out.println(list);
        System.out.println(list.getClass());
    }
}
class CallHandler<E> implements InvocationHandler{
    List<E> target = new ArrayList<>();
    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        System.out.println(method);
        synchronized (target) {
            //
            Object value = method.invoke(target, args);
            //
            return value;
        }
    }
}
